namespace KPIS.GERP.SERVICE.Model.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class initial : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "hrm_ps_absence",
                c => new
                    {
                        absence_seq = c.Int(nullable: false, identity: true),
                        absence_type_seq = c.Int(),
                        bgm_year = c.Int(),
                        emp_seq = c.Int(),
                        start_date = c.DateTime(),
                        start_time = c.String(),
                        end_date = c.DateTime(),
                        end_time = c.String(),
                        day_count = c.Decimal(precision: 18, scale: 2),
                        contact_address = c.String(),
                        remarks = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                        description = c.String(),
                    })
                .PrimaryKey(t => t.absence_seq)
                .ForeignKey("hrm_ps_absence_type", t => t.absence_type_seq)
                .ForeignKey("hrm_ps_employees", t => t.emp_seq)
                .Index(t => t.absence_type_seq)
                .Index(t => t.emp_seq);
            
            CreateTable(
                "hrm_ps_absence_type",
                c => new
                    {
                        absence_type_seq = c.Int(nullable: false, identity: true),
                        absence_type_name = c.String(),
                        remarks = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.absence_type_seq);
            
            CreateTable(
                "hrm_ps_employees",
                c => new
                    {
                        emp_seq = c.Int(nullable: false, identity: true),
                        name_prefix_seq = c.Int(),
                        first_name = c.String(),
                        last_name = c.String(),
                        first_name_eng = c.String(),
                        last_name_eng = c.String(),
                        nick_name = c.String(),
                        gender_seq = c.Int(),
                        religion_seq = c.Int(),
                        race_nat_seq = c.Int(),
                        nat_seq = c.Int(),
                        birth_date = c.DateTime(),
                        emp_type_seq = c.Int(),
                        class_seq = c.Int(),
                        salary_level_seq = c.Int(),
                        salary = c.Double(),
                        pos_seq = c.Int(),
                        working_job_site_seq = c.Int(),
                        working_job_site_text = c.String(),
                        date_admitted = c.DateTime(),
                        date_work_start = c.DateTime(),
                        date_quit = c.DateTime(),
                        emp_status_seq = c.Int(),
                        emp_sec_seq = c.Int(),
                        citizen = c.String(),
                        tax_payer = c.String(),
                        social = c.String(),
                        official = c.String(),
                        blood_group_seq = c.Int(),
                        probation_date_end = c.DateTime(),
                        death_date = c.DateTime(),
                        date_latest_pos = c.DateTime(),
                        date_latest_class = c.DateTime(),
                        date_latest_working_job_site = c.DateTime(),
                        exec_pos_seq = c.Int(),
                        fund_member = c.Int(),
                        mar_stat_seq = c.Int(),
                        move_seq = c.Int(),
                        old_class_seq = c.Int(),
                        code_scan = c.String(),
                        cmd_ref_no = c.String(),
                        record_status = c.String(),
                        remarks = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                        image_unique = c.String(),
                    })
                .PrimaryKey(t => t.emp_seq)
                .ForeignKey("mas_name_prefixes", t => t.name_prefix_seq)
                .ForeignKey("mas_genders", t => t.gender_seq)
                .ForeignKey("mas_religions", t => t.religion_seq)
                .ForeignKey("mas_nationalities", t => t.race_nat_seq)
                .ForeignKey("mas_nationalities", t => t.nat_seq)
                .ForeignKey("hrm_ps_employee_types", t => t.emp_type_seq)
                .ForeignKey("hrm_mp_classes", t => t.class_seq)
                .ForeignKey("hrm_mp_classes", t => t.old_class_seq)
                .ForeignKey("hrm_mp_positions", t => t.pos_seq)
                .ForeignKey("hrm_mp_job_sites", t => t.working_job_site_seq)
                .ForeignKey("hrm_ps_employee_statuses", t => t.emp_status_seq)
                .ForeignKey("mas_blood_groups", t => t.blood_group_seq)
                .ForeignKey("hrm_mp_exec_positions", t => t.exec_pos_seq)
                .ForeignKey("mas_marital_statuses", t => t.mar_stat_seq)
                .Index(t => t.name_prefix_seq)
                .Index(t => t.gender_seq)
                .Index(t => t.religion_seq)
                .Index(t => t.race_nat_seq)
                .Index(t => t.nat_seq)
                .Index(t => t.emp_type_seq)
                .Index(t => t.class_seq)
                .Index(t => t.old_class_seq)
                .Index(t => t.pos_seq)
                .Index(t => t.working_job_site_seq)
                .Index(t => t.emp_status_seq)
                .Index(t => t.blood_group_seq)
                .Index(t => t.exec_pos_seq)
                .Index(t => t.mar_stat_seq);
            
            CreateTable(
                "mas_name_prefixes",
                c => new
                    {
                        name_prefix_seq = c.Int(nullable: false, identity: true),
                        prefix_code = c.String(),
                        prefix_name = c.String(),
                        prefix_name_eng = c.String(),
                        prefix_short = c.String(),
                        prefix_short_eng = c.String(),
                        gender_seq = c.Int(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.name_prefix_seq)
                .ForeignKey("mas_genders", t => t.gender_seq)
                .Index(t => t.gender_seq);
            
            CreateTable(
                "mas_genders",
                c => new
                    {
                        gender_seq = c.Int(nullable: false, identity: true),
                        gender_name = c.String(),
                        gender_name_eng = c.String(),
                        gender_thai = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.gender_seq);
            
            CreateTable(
                "mas_religions",
                c => new
                    {
                        religion_seq = c.Int(nullable: false, identity: true),
                        religion_code = c.String(),
                        religion_name = c.String(),
                        religion_name_eng = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.religion_seq);
            
            CreateTable(
                "mas_nationalities",
                c => new
                    {
                        nat_seq = c.Int(nullable: false, identity: true),
                        nat_name = c.String(),
                        nat_name_eng = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.nat_seq);
            
            CreateTable(
                "hrm_ps_employee_types",
                c => new
                    {
                        emp_type_seq = c.Int(nullable: false, identity: true),
                        emp_type_name = c.String(),
                        salary_up_time = c.Int(),
                        retirements = c.Int(),
                        royalitems = c.Int(),
                        year_type_seq = c.Int(),
                        remarks = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.emp_type_seq);
            
            CreateTable(
                "hrm_mp_classes",
                c => new
                    {
                        class_seq = c.Int(nullable: false, identity: true),
                        class_no = c.String(),
                        class_name = c.String(),
                        class_name_short = c.String(),
                        class_eng = c.String(),
                        class_eng_short = c.String(),
                        pos_type_seq = c.Int(),
                        emp_type_seq = c.Int(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                        remarks = c.String(),
                    })
                .PrimaryKey(t => t.class_seq)
                .ForeignKey("hrm_mp_position_types", t => t.pos_type_seq)
                .ForeignKey("hrm_ps_employee_types", t => t.emp_type_seq)
                .Index(t => t.pos_type_seq)
                .Index(t => t.emp_type_seq);
            
            CreateTable(
                "hrm_mp_position_types",
                c => new
                    {
                        pos_type_seq = c.Int(nullable: false, identity: true),
                        pos_type_name = c.String(),
                        pos_type_name_short = c.String(),
                        pos_type_eng = c.String(),
                        pos_type_eng_short = c.String(),
                        emp_type_seq = c.Int(),
                        remarks = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.pos_type_seq)
                .ForeignKey("hrm_ps_employee_types", t => t.emp_type_seq)
                .Index(t => t.emp_type_seq);
            
            CreateTable(
                "hrm_mp_positions",
                c => new
                    {
                        pos_seq = c.Int(nullable: false, identity: true),
                        pos_ref = c.String(),
                        pos_name = c.String(),
                        field_pos_seq = c.Int(),
                        exec_pos_seq = c.Int(),
                        emp_type_seq = c.Int(),
                        date_defined = c.DateTime(),
                        date_money_support = c.DateTime(),
                        date_changed = c.DateTime(),
                        change_ref_no = c.String(),
                        salary_quota = c.Double(),
                        last_salary_quota = c.Double(),
                        job_site_seq = c.Int(),
                        pos_status = c.String(),
                        salary_min = c.Double(),
                        salary_max = c.Double(),
                        pos_exec_salary = c.Double(),
                        class_spec_seq = c.Int(),
                        pos_upper_seq = c.Int(),
                        pos_working_upper_seq = c.Int(),
                        job_description = c.String(),
                        skill_seq = c.Int(),
                        remarks = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                        salary_glow = c.Double(),
                        currency_seq = c.Int(),
                    })
                .PrimaryKey(t => t.pos_seq)
                .ForeignKey("hrm_mp_field_positions", t => t.field_pos_seq)
                .ForeignKey("hrm_mp_exec_positions", t => t.exec_pos_seq)
                .ForeignKey("hrm_ps_employee_types", t => t.emp_type_seq)
                .ForeignKey("hrm_mp_job_sites", t => t.job_site_seq)
                .ForeignKey("hrm_mp_class_specifications", t => t.class_spec_seq)
                .ForeignKey("hrm_mp_position_skill", t => t.skill_seq)
                .ForeignKey("fim_mas_currencies", t => t.currency_seq)
                .Index(t => t.field_pos_seq)
                .Index(t => t.exec_pos_seq)
                .Index(t => t.emp_type_seq)
                .Index(t => t.job_site_seq)
                .Index(t => t.class_spec_seq)
                .Index(t => t.skill_seq)
                .Index(t => t.currency_seq);
            
            CreateTable(
                "hrm_mp_field_positions",
                c => new
                    {
                        field_pos_seq = c.Int(nullable: false, identity: true),
                        field_pos_code = c.String(),
                        field_pos_name = c.String(),
                        field_pos_name_eng = c.String(),
                        field_pos_line = c.String(),
                        field_pos_line_short = c.String(),
                        field_pos_line_eng = c.String(),
                        emp_type_seq = c.Int(),
                        pos_type_seq = c.Int(),
                        field_group_seq = c.Int(),
                        class_spec_seq = c.Int(),
                        field_pos_seq_new = c.Int(),
                        remarks = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.field_pos_seq)
                .ForeignKey("hrm_ps_employee_types", t => t.emp_type_seq)
                .ForeignKey("hrm_mp_position_types", t => t.pos_type_seq)
                .ForeignKey("hrm_mp_field_groups", t => t.field_group_seq)
                .ForeignKey("hrm_mp_class_specifications", t => t.class_spec_seq)
                .Index(t => t.emp_type_seq)
                .Index(t => t.pos_type_seq)
                .Index(t => t.field_group_seq)
                .Index(t => t.class_spec_seq);
            
            CreateTable(
                "hrm_mp_field_groups",
                c => new
                    {
                        field_group_seq = c.Int(nullable: false, identity: true),
                        field_group_name = c.String(),
                        field_group_descr = c.String(),
                        emp_type_seq = c.Int(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.field_group_seq);
            
            CreateTable(
                "hrm_mp_class_specifications",
                c => new
                    {
                        class_spec_seq = c.Int(nullable: false, identity: true),
                        class_spec_name = c.String(),
                        class_spec_eng = c.String(),
                        pos_type_seq = c.Int(),
                        class_max = c.Int(),
                        class_min = c.Int(),
                        remarks = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.class_spec_seq);
            
            CreateTable(
                "hrm_mp_exec_positions",
                c => new
                    {
                        exec_pos_seq = c.Int(nullable: false, identity: true),
                        exec_pos_code = c.String(),
                        exec_pos_name = c.String(),
                        exec_pos_name_short = c.String(),
                        exec_pos_name_eng = c.String(),
                        exec_pos_name_eng_short = c.String(),
                        exec_pos_group_seq = c.Int(),
                        job_family_seq = c.Int(),
                        remarks = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.exec_pos_seq);
            
            CreateTable(
                "hrm_mp_job_sites",
                c => new
                    {
                        job_site_seq = c.Int(nullable: false, identity: true),
                        job_site_ref = c.String(),
                        job_site_name = c.String(),
                        job_site_name_short = c.String(),
                        job_site_name_eng = c.String(),
                        job_site_name_eng_short = c.String(),
                        job_site_upper_seq = c.Int(),
                        job_site_full_path = c.String(),
                        job_site_type_seq = c.Int(nullable: false),
                        work_area_seq = c.Int(),
                        job_site_gfmis = c.String(),
                        job_site_level_seq = c.Int(),
                        job_description = c.String(),
                        address = c.String(),
                        district_seq = c.Int(),
                        prov_seq = c.Int(),
                        city_seq = c.Int(),
                        country_seq = c.Int(),
                        postal_code = c.String(),
                        tel = c.String(),
                        fax = c.String(),
                        job_site_ref_seq = c.Int(),
                        date_start = c.DateTime(),
                        date_end = c.DateTime(),
                        job_site_stat_seq = c.Int(),
                        currency_seq = c.Int(),
                        remarks = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                        address2 = c.String(),
                        webaddress = c.String(),
                        head_pos_seq = c.Int(),
                    })
                .PrimaryKey(t => t.job_site_seq);
            
            CreateTable(
                "hrm_mp_position_skill",
                c => new
                    {
                        skill_seq = c.Int(nullable: false, identity: true),
                        skill_code = c.String(),
                        skill_name = c.String(),
                        skill_grp_seq = c.Int(),
                        remarks = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.skill_seq);
            
            CreateTable(
                "fim_mas_currencies",
                c => new
                    {
                        currency_seq = c.Int(nullable: false, identity: true),
                        currency_name = c.String(),
                        currency_name_short = c.String(),
                        currency_name_eng = c.String(),
                        currency_name_eng_short = c.String(),
                        remarks = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.currency_seq);
            
            CreateTable(
                "hrm_ps_employee_statuses",
                c => new
                    {
                        emp_status_seq = c.Int(nullable: false, identity: true),
                        emp_status_name = c.String(),
                        active = c.String(),
                        emp_status_code = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.emp_status_seq);
            
            CreateTable(
                "mas_blood_groups",
                c => new
                    {
                        blood_group_seq = c.Int(nullable: false, identity: true),
                        blood_group_name = c.String(),
                        blood_group_name_eng = c.String(),
                        record_status = c.String(),
                        remarks = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.blood_group_seq);
            
            CreateTable(
                "mas_marital_statuses",
                c => new
                    {
                        mar_stat_seq = c.Int(nullable: false, identity: true),
                        mar_stat_name = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.mar_stat_seq);
            
            CreateTable(
                "mas_districts",
                c => new
                    {
                        district_seq = c.Int(nullable: false, identity: true),
                        district_code = c.String(),
                        district_name = c.String(),
                        district_name_eng = c.String(),
                        amp_seq = c.Int(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.district_seq)
                .ForeignKey("mas_amphurs", t => t.amp_seq)
                .Index(t => t.amp_seq);
            
            CreateTable(
                "mas_amphurs",
                c => new
                    {
                        amp_seq = c.Int(nullable: false, identity: true),
                        amp_code = c.String(),
                        amp_name = c.String(),
                        amp_name_eng = c.String(),
                        prov_seq = c.Int(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.amp_seq)
                .ForeignKey("mas_provinces", t => t.prov_seq)
                .Index(t => t.prov_seq);
            
            CreateTable(
                "mas_provinces",
                c => new
                    {
                        prov_seq = c.Int(nullable: false, identity: true),
                        prov_name = c.String(),
                        prov_name_eng = c.String(),
                        region_seq = c.Int(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                        prov_code = c.String(),
                    })
                .PrimaryKey(t => t.prov_seq);
            
            CreateTable(
                "message",
                c => new
                    {
                        message_seq = c.Int(nullable: false, identity: true),
                        message_no = c.String(),
                        message_date = c.DateTime(),
                        message_title = c.String(),
                        message_descr = c.String(),
                        from_emp_seq = c.Int(),
                        to_emp_seq = c.Int(),
                        from_message_seq = c.Int(),
                        approval_task_seq = c.Int(),
                        remarks = c.String(),
                        message_status = c.String(),
                        message_status_string = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                        action_count = c.Int(nullable: false),
                        from_message_message_seq = c.Int(),
                    })
                .PrimaryKey(t => t.message_seq)
                .ForeignKey("message", t => t.from_message_message_seq)
                .Index(t => t.from_message_message_seq);
            
            CreateTable(
                "sys_sc_users",
                c => new
                    {
                        user_seq = c.Int(nullable: false, identity: true),
                        emp_seq = c.Int(),
                        user_code = c.String(nullable: false),
                        user_password = c.String(nullable: false),
                        user_first_name = c.String(),
                        user_last_name = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                        user_citizen = c.String(),
                        user_job_site_seq = c.Int(),
                        user_pos_seq = c.Int(),
                        user_status = c.String(),
                        record_status = c.String(),
                    })
                .PrimaryKey(t => t.user_seq)
                .ForeignKey("hrm_ps_employees", t => t.emp_seq)
                .Index(t => t.emp_seq);
            
            CreateTable(
                "sys_sc_user_roles",
                c => new
                    {
                        user_role_seq = c.Int(nullable: false, identity: true),
                        user_seq = c.Int(nullable: false),
                        pos_seq = c.Int(),
                        role_seq = c.Int(nullable: false),
                        emp_type_seq = c.Int(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.user_role_seq)
                .ForeignKey("sys_sc_users", t => t.user_seq, cascadeDelete: true)
                .ForeignKey("sys_sc_roles", t => t.role_seq, cascadeDelete: true)
                .Index(t => t.user_seq)
                .Index(t => t.role_seq);
            
            CreateTable(
                "sys_sc_roles",
                c => new
                    {
                        role_seq = c.Int(nullable: false, identity: true),
                        role_name = c.String(),
                        system = c.String(),
                        remarks = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.role_seq);
            
            CreateTable(
                "sys_sc_permissions",
                c => new
                    {
                        permission_seq = c.Int(nullable: false, identity: true),
                        role_seq = c.Int(nullable: false),
                        menu_item_seq = c.Int(nullable: false),
                        permission_type = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.permission_seq)
                .ForeignKey("sys_sc_roles", t => t.role_seq, cascadeDelete: true)
                .ForeignKey("sys_menu_items_list", t => t.menu_item_seq, cascadeDelete: true)
                .Index(t => t.role_seq)
                .Index(t => t.menu_item_seq);
            
            CreateTable(
                "sys_menu_items_list",
                c => new
                    {
                        menu_item_seq = c.Int(nullable: false, identity: true),
                        menu_item_code = c.String(),
                        menu_item_name = c.String(),
                        upper_menu_item_seq = c.Int(),
                        menu_item_path = c.String(),
                        menu_item_target = c.String(),
                        system_id = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.menu_item_seq)
                .ForeignKey("sys_menu_items_list", t => t.upper_menu_item_seq)
                .Index(t => t.upper_menu_item_seq);
            
            CreateTable(
                "hrm_ps_commands",
                c => new
                    {
                        cmd_seq = c.Int(nullable: false, identity: true),
                        cmd_flag = c.String(nullable: false),
                        cmd_draft_no = c.String(),
                        cmd_name = c.String(nullable: false),
                        cmd_descr = c.String(unicode: false, storeType: "text"),
                        cmd_ref_no = c.String(nullable: false),
                        cmd_type_seq = c.Int(nullable: false),
                        emp_type_seq = c.Int(nullable: false),
                        job_site_seq = c.Int(),
                        penalty_seq = c.Int(),
                        cmd_status = c.String(),
                        approved_seq = c.Int(),
                        approved_name = c.String(),
                        approved_positions = c.String(),
                        approved_date = c.DateTime(),
                        cmd_rpt_date = c.String(),
                        inv_type_seq = c.Int(),
                        confirm = c.Int(),
                        rpt_header = c.String(),
                        remarks = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.cmd_seq)
                .ForeignKey("hrm_ps_command_types", t => t.cmd_type_seq, cascadeDelete: true)
                .ForeignKey("hrm_ps_employee_types", t => t.emp_type_seq, cascadeDelete: true)
                .ForeignKey("hrm_mp_job_sites", t => t.job_site_seq)
                .ForeignKey("hrm_ps_employees", t => t.approved_seq)
                .ForeignKey("hrm_dc_penalty", t => t.penalty_seq)
                .Index(t => t.cmd_type_seq)
                .Index(t => t.emp_type_seq)
                .Index(t => t.job_site_seq)
                .Index(t => t.approved_seq)
                .Index(t => t.penalty_seq);
            
            CreateTable(
                "hrm_ps_command_types",
                c => new
                    {
                        cmd_type_seq = c.Int(nullable: false, identity: true),
                        cmd_type_code = c.String(),
                        cmd_type_name = c.String(),
                        cmd_type_name_short = c.String(),
                        cmd_group_seq = c.Int(),
                        rpt_format = c.String(),
                        remarks = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                        rpt_header = c.String(),
                    })
                .PrimaryKey(t => t.cmd_type_seq)
                .ForeignKey("hrm_ps_command_groups", t => t.cmd_group_seq)
                .Index(t => t.cmd_group_seq);
            
            CreateTable(
                "hrm_ps_command_groups",
                c => new
                    {
                        cmd_group_seq = c.Int(nullable: false, identity: true),
                        cmd_group_name = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.cmd_group_seq);
            
            CreateTable(
                "hrm_dc_penalty",
                c => new
                    {
                        pen_seq = c.Int(nullable: false, identity: true),
                        pen_name = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.pen_seq);
            
            CreateTable(
                "hrm_ps_command_dtls",
                c => new
                    {
                        cmd_dtls_seq = c.Int(nullable: false, identity: true),
                        cmd_seq = c.Int(nullable: false),
                        emp_seq = c.Int(nullable: false),
                        start_date = c.DateTime(nullable: false),
                        end_date = c.DateTime(),
                        edu_his_seq = c.Int(),
                        remarks = c.String(),
                        rpt_remarks = c.String(),
                        move_seq = c.Int(),
                        old_pos_seq = c.Int(),
                        old_pos_ref = c.String(),
                        old_pos_name = c.String(),
                        old_exec_pos_name = c.String(),
                        old_class_seq = c.Int(),
                        old_job_site_seq = c.Int(),
                        old_job_site_name = c.String(),
                        old_working_job_site_seq = c.Int(),
                        old_working_job_site_name = c.String(),
                        old_salary = c.Double(),
                        old_exec_salary = c.Double(),
                        old_pos_line = c.String(),
                        old_pos_type_seq = c.Int(),
                        old_exec_pos_seq = c.Int(),
                        new_pos_seq = c.Int(),
                        new_pos_ref = c.String(),
                        new_pos_name = c.String(),
                        new_exec_pos_name = c.String(),
                        new_class_seq = c.Int(),
                        new_job_site_seq = c.Int(),
                        new_job_site_name = c.String(),
                        new_working_job_site_seq = c.Int(),
                        new_working_job_site_name = c.String(),
                        new_salary = c.Double(),
                        new_exec_salary = c.Double(),
                        new_pos_line = c.String(),
                        new_pos_type_seq = c.Int(),
                        new_exec_pos_seq = c.Int(),
                        old_dep_name = c.String(),
                        old_working_dep_name = c.String(),
                        new_dep_name = c.String(),
                        new_working_dep_name = c.String(),
                        prm_base = c.Double(),
                        prm_percent = c.Decimal(precision: 18, scale: 2),
                        prm_amount = c.Double(),
                        remarks2 = c.String(),
                        ent_no = c.Int(),
                        ent_pos_name = c.String(),
                        ent_pos_type_seq = c.Int(),
                        ent_class_seq = c.Int(),
                        ent_job_site_name = c.String(),
                        ent_date = c.DateTime(),
                        back_date = c.DateTime(),
                        tmp_emp_seq = c.Int(),
                        tmp_edu_seq = c.Int(),
                        curr_pos_class_date = c.DateTime(),
                        quit_date = c.DateTime(),
                        currency_seq = c.Int(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.cmd_dtls_seq)
                .ForeignKey("hrm_ps_commands", t => t.cmd_seq, cascadeDelete: true)
                .ForeignKey("hrm_ps_employees", t => t.emp_seq, cascadeDelete: true)
                .ForeignKey("hrm_mp_positions", t => t.old_pos_seq)
                .ForeignKey("hrm_mp_classes", t => t.old_class_seq)
                .ForeignKey("hrm_mp_job_sites", t => t.old_job_site_seq)
                .ForeignKey("hrm_mp_job_sites", t => t.old_working_job_site_seq)
                .ForeignKey("hrm_mp_exec_positions", t => t.old_exec_pos_seq)
                .ForeignKey("hrm_mp_positions", t => t.new_pos_seq)
                .ForeignKey("hrm_mp_classes", t => t.new_class_seq)
                .ForeignKey("hrm_mp_job_sites", t => t.new_job_site_seq)
                .ForeignKey("hrm_mp_job_sites", t => t.new_working_job_site_seq)
                .ForeignKey("hrm_mp_exec_positions", t => t.new_exec_pos_seq)
                .Index(t => t.cmd_seq)
                .Index(t => t.emp_seq)
                .Index(t => t.old_pos_seq)
                .Index(t => t.old_class_seq)
                .Index(t => t.old_job_site_seq)
                .Index(t => t.old_working_job_site_seq)
                .Index(t => t.old_exec_pos_seq)
                .Index(t => t.new_pos_seq)
                .Index(t => t.new_class_seq)
                .Index(t => t.new_job_site_seq)
                .Index(t => t.new_working_job_site_seq)
                .Index(t => t.new_exec_pos_seq);
            
            CreateTable(
                "hrm_ps_emp_position_histories",
                c => new
                    {
                        pos_his_seq = c.Int(nullable: false, identity: true),
                        emp_seq = c.Int(),
                        start_date = c.DateTime(),
                        end_date = c.DateTime(),
                        cmd_dtls_seq = c.Int(),
                        cmd_ref_no = c.String(),
                        cmd_date = c.DateTime(),
                        cmd_name = c.String(),
                        cmd_pos_ref = c.String(),
                        cmd_pos_name = c.String(),
                        cmd_class_seq = c.Int(),
                        cmd_class_name = c.String(),
                        cmd_job_site_seq = c.Int(),
                        cmd_job_site_name = c.String(),
                        cmd_working_job_site_name = c.String(),
                        cmd_dep_name = c.String(),
                        cmd_mis_name = c.String(),
                        cmd_field_seq = c.Int(),
                        cmd_field_name = c.String(),
                        cmd_exec_seq = c.Int(),
                        cmd_exec_name = c.String(),
                        cmd_salary = c.Double(),
                        cmd_salary_position = c.Double(),
                        salary = c.Double(),
                        pos_ref = c.String(),
                        pos_name = c.String(),
                        class_seq = c.Int(),
                        class_name = c.String(),
                        job_site_seq = c.Int(),
                        job_site_name = c.String(),
                        move_seq = c.Int(),
                        remarks = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                        cmd_type_seq = c.Int(),
                        his_type = c.String(),
                        working_job_site_name = c.String(),
                        department_name = c.String(),
                        ministry_name = c.String(),
                        field_name = c.String(),
                        exec_name = c.String(),
                    })
                .PrimaryKey(t => t.pos_his_seq);
            
            CreateTable(
                "hrm_ps_emp_salary_histories",
                c => new
                    {
                        sal_his_seq = c.Int(nullable: false, identity: true),
                        emp_seq = c.Int(),
                        start_date = c.DateTime(),
                        end_date = c.DateTime(),
                        cmd_ref_no = c.String(),
                        cmd_name = c.String(),
                        cmd_date = c.DateTime(),
                        pos_ref = c.String(),
                        pos_name = c.String(),
                        class_seq = c.Int(),
                        class_name = c.String(),
                        job_site_seq = c.Int(),
                        job_site_name = c.String(),
                        salary_new = c.Double(),
                        salary_old = c.Double(),
                        salary_percent_up = c.Double(),
                        salary_up = c.Double(),
                        salary_midpoint = c.Double(),
                        salary_extra = c.Double(),
                        salary_extra_seq = c.Int(),
                        total_score = c.Double(),
                        move_seq = c.Int(),
                        remarks = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.sal_his_seq);
            
        }
        
        public override void Down()
        {
            DropIndex("hrm_ps_command_dtls", new[] { "new_exec_pos_seq" });
            DropIndex("hrm_ps_command_dtls", new[] { "new_working_job_site_seq" });
            DropIndex("hrm_ps_command_dtls", new[] { "new_job_site_seq" });
            DropIndex("hrm_ps_command_dtls", new[] { "new_class_seq" });
            DropIndex("hrm_ps_command_dtls", new[] { "new_pos_seq" });
            DropIndex("hrm_ps_command_dtls", new[] { "old_exec_pos_seq" });
            DropIndex("hrm_ps_command_dtls", new[] { "old_working_job_site_seq" });
            DropIndex("hrm_ps_command_dtls", new[] { "old_job_site_seq" });
            DropIndex("hrm_ps_command_dtls", new[] { "old_class_seq" });
            DropIndex("hrm_ps_command_dtls", new[] { "old_pos_seq" });
            DropIndex("hrm_ps_command_dtls", new[] { "emp_seq" });
            DropIndex("hrm_ps_command_dtls", new[] { "cmd_seq" });
            DropIndex("hrm_ps_command_types", new[] { "cmd_group_seq" });
            DropIndex("hrm_ps_commands", new[] { "penalty_seq" });
            DropIndex("hrm_ps_commands", new[] { "approved_seq" });
            DropIndex("hrm_ps_commands", new[] { "job_site_seq" });
            DropIndex("hrm_ps_commands", new[] { "emp_type_seq" });
            DropIndex("hrm_ps_commands", new[] { "cmd_type_seq" });
            DropIndex("sys_menu_items_list", new[] { "upper_menu_item_seq" });
            DropIndex("sys_sc_permissions", new[] { "menu_item_seq" });
            DropIndex("sys_sc_permissions", new[] { "role_seq" });
            DropIndex("sys_sc_user_roles", new[] { "role_seq" });
            DropIndex("sys_sc_user_roles", new[] { "user_seq" });
            DropIndex("sys_sc_users", new[] { "emp_seq" });
            DropIndex("message", new[] { "from_message_message_seq" });
            DropIndex("mas_amphurs", new[] { "prov_seq" });
            DropIndex("mas_districts", new[] { "amp_seq" });
            DropIndex("hrm_mp_field_positions", new[] { "class_spec_seq" });
            DropIndex("hrm_mp_field_positions", new[] { "field_group_seq" });
            DropIndex("hrm_mp_field_positions", new[] { "pos_type_seq" });
            DropIndex("hrm_mp_field_positions", new[] { "emp_type_seq" });
            DropIndex("hrm_mp_positions", new[] { "currency_seq" });
            DropIndex("hrm_mp_positions", new[] { "skill_seq" });
            DropIndex("hrm_mp_positions", new[] { "class_spec_seq" });
            DropIndex("hrm_mp_positions", new[] { "job_site_seq" });
            DropIndex("hrm_mp_positions", new[] { "emp_type_seq" });
            DropIndex("hrm_mp_positions", new[] { "exec_pos_seq" });
            DropIndex("hrm_mp_positions", new[] { "field_pos_seq" });
            DropIndex("hrm_mp_position_types", new[] { "emp_type_seq" });
            DropIndex("hrm_mp_classes", new[] { "emp_type_seq" });
            DropIndex("hrm_mp_classes", new[] { "pos_type_seq" });
            DropIndex("mas_name_prefixes", new[] { "gender_seq" });
            DropIndex("hrm_ps_employees", new[] { "mar_stat_seq" });
            DropIndex("hrm_ps_employees", new[] { "exec_pos_seq" });
            DropIndex("hrm_ps_employees", new[] { "blood_group_seq" });
            DropIndex("hrm_ps_employees", new[] { "emp_status_seq" });
            DropIndex("hrm_ps_employees", new[] { "working_job_site_seq" });
            DropIndex("hrm_ps_employees", new[] { "pos_seq" });
            DropIndex("hrm_ps_employees", new[] { "old_class_seq" });
            DropIndex("hrm_ps_employees", new[] { "class_seq" });
            DropIndex("hrm_ps_employees", new[] { "emp_type_seq" });
            DropIndex("hrm_ps_employees", new[] { "nat_seq" });
            DropIndex("hrm_ps_employees", new[] { "race_nat_seq" });
            DropIndex("hrm_ps_employees", new[] { "religion_seq" });
            DropIndex("hrm_ps_employees", new[] { "gender_seq" });
            DropIndex("hrm_ps_employees", new[] { "name_prefix_seq" });
            DropIndex("hrm_ps_absence", new[] { "emp_seq" });
            DropIndex("hrm_ps_absence", new[] { "absence_type_seq" });
            DropForeignKey("hrm_ps_command_dtls", "new_exec_pos_seq", "hrm_mp_exec_positions");
            DropForeignKey("hrm_ps_command_dtls", "new_working_job_site_seq", "hrm_mp_job_sites");
            DropForeignKey("hrm_ps_command_dtls", "new_job_site_seq", "hrm_mp_job_sites");
            DropForeignKey("hrm_ps_command_dtls", "new_class_seq", "hrm_mp_classes");
            DropForeignKey("hrm_ps_command_dtls", "new_pos_seq", "hrm_mp_positions");
            DropForeignKey("hrm_ps_command_dtls", "old_exec_pos_seq", "hrm_mp_exec_positions");
            DropForeignKey("hrm_ps_command_dtls", "old_working_job_site_seq", "hrm_mp_job_sites");
            DropForeignKey("hrm_ps_command_dtls", "old_job_site_seq", "hrm_mp_job_sites");
            DropForeignKey("hrm_ps_command_dtls", "old_class_seq", "hrm_mp_classes");
            DropForeignKey("hrm_ps_command_dtls", "old_pos_seq", "hrm_mp_positions");
            DropForeignKey("hrm_ps_command_dtls", "emp_seq", "hrm_ps_employees");
            DropForeignKey("hrm_ps_command_dtls", "cmd_seq", "hrm_ps_commands");
            DropForeignKey("hrm_ps_command_types", "cmd_group_seq", "hrm_ps_command_groups");
            DropForeignKey("hrm_ps_commands", "penalty_seq", "hrm_dc_penalty");
            DropForeignKey("hrm_ps_commands", "approved_seq", "hrm_ps_employees");
            DropForeignKey("hrm_ps_commands", "job_site_seq", "hrm_mp_job_sites");
            DropForeignKey("hrm_ps_commands", "emp_type_seq", "hrm_ps_employee_types");
            DropForeignKey("hrm_ps_commands", "cmd_type_seq", "hrm_ps_command_types");
            DropForeignKey("sys_menu_items_list", "upper_menu_item_seq", "sys_menu_items_list");
            DropForeignKey("sys_sc_permissions", "menu_item_seq", "sys_menu_items_list");
            DropForeignKey("sys_sc_permissions", "role_seq", "sys_sc_roles");
            DropForeignKey("sys_sc_user_roles", "role_seq", "sys_sc_roles");
            DropForeignKey("sys_sc_user_roles", "user_seq", "sys_sc_users");
            DropForeignKey("sys_sc_users", "emp_seq", "hrm_ps_employees");
            DropForeignKey("message", "from_message_message_seq", "message");
            DropForeignKey("mas_amphurs", "prov_seq", "mas_provinces");
            DropForeignKey("mas_districts", "amp_seq", "mas_amphurs");
            DropForeignKey("hrm_mp_field_positions", "class_spec_seq", "hrm_mp_class_specifications");
            DropForeignKey("hrm_mp_field_positions", "field_group_seq", "hrm_mp_field_groups");
            DropForeignKey("hrm_mp_field_positions", "pos_type_seq", "hrm_mp_position_types");
            DropForeignKey("hrm_mp_field_positions", "emp_type_seq", "hrm_ps_employee_types");
            DropForeignKey("hrm_mp_positions", "currency_seq", "fim_mas_currencies");
            DropForeignKey("hrm_mp_positions", "skill_seq", "hrm_mp_position_skill");
            DropForeignKey("hrm_mp_positions", "class_spec_seq", "hrm_mp_class_specifications");
            DropForeignKey("hrm_mp_positions", "job_site_seq", "hrm_mp_job_sites");
            DropForeignKey("hrm_mp_positions", "emp_type_seq", "hrm_ps_employee_types");
            DropForeignKey("hrm_mp_positions", "exec_pos_seq", "hrm_mp_exec_positions");
            DropForeignKey("hrm_mp_positions", "field_pos_seq", "hrm_mp_field_positions");
            DropForeignKey("hrm_mp_position_types", "emp_type_seq", "hrm_ps_employee_types");
            DropForeignKey("hrm_mp_classes", "emp_type_seq", "hrm_ps_employee_types");
            DropForeignKey("hrm_mp_classes", "pos_type_seq", "hrm_mp_position_types");
            DropForeignKey("mas_name_prefixes", "gender_seq", "mas_genders");
            DropForeignKey("hrm_ps_employees", "mar_stat_seq", "mas_marital_statuses");
            DropForeignKey("hrm_ps_employees", "exec_pos_seq", "hrm_mp_exec_positions");
            DropForeignKey("hrm_ps_employees", "blood_group_seq", "mas_blood_groups");
            DropForeignKey("hrm_ps_employees", "emp_status_seq", "hrm_ps_employee_statuses");
            DropForeignKey("hrm_ps_employees", "working_job_site_seq", "hrm_mp_job_sites");
            DropForeignKey("hrm_ps_employees", "pos_seq", "hrm_mp_positions");
            DropForeignKey("hrm_ps_employees", "old_class_seq", "hrm_mp_classes");
            DropForeignKey("hrm_ps_employees", "class_seq", "hrm_mp_classes");
            DropForeignKey("hrm_ps_employees", "emp_type_seq", "hrm_ps_employee_types");
            DropForeignKey("hrm_ps_employees", "nat_seq", "mas_nationalities");
            DropForeignKey("hrm_ps_employees", "race_nat_seq", "mas_nationalities");
            DropForeignKey("hrm_ps_employees", "religion_seq", "mas_religions");
            DropForeignKey("hrm_ps_employees", "gender_seq", "mas_genders");
            DropForeignKey("hrm_ps_employees", "name_prefix_seq", "mas_name_prefixes");
            DropForeignKey("hrm_ps_absence", "emp_seq", "hrm_ps_employees");
            DropForeignKey("hrm_ps_absence", "absence_type_seq", "hrm_ps_absence_type");
            DropTable("hrm_ps_emp_salary_histories");
            DropTable("hrm_ps_emp_position_histories");
            DropTable("hrm_ps_command_dtls");
            DropTable("hrm_dc_penalty");
            DropTable("hrm_ps_command_groups");
            DropTable("hrm_ps_command_types");
            DropTable("hrm_ps_commands");
            DropTable("sys_menu_items_list");
            DropTable("sys_sc_permissions");
            DropTable("sys_sc_roles");
            DropTable("sys_sc_user_roles");
            DropTable("sys_sc_users");
            DropTable("message");
            DropTable("mas_provinces");
            DropTable("mas_amphurs");
            DropTable("mas_districts");
            DropTable("mas_marital_statuses");
            DropTable("mas_blood_groups");
            DropTable("hrm_ps_employee_statuses");
            DropTable("fim_mas_currencies");
            DropTable("hrm_mp_position_skill");
            DropTable("hrm_mp_job_sites");
            DropTable("hrm_mp_exec_positions");
            DropTable("hrm_mp_class_specifications");
            DropTable("hrm_mp_field_groups");
            DropTable("hrm_mp_field_positions");
            DropTable("hrm_mp_positions");
            DropTable("hrm_mp_position_types");
            DropTable("hrm_mp_classes");
            DropTable("hrm_ps_employee_types");
            DropTable("mas_nationalities");
            DropTable("mas_religions");
            DropTable("mas_genders");
            DropTable("mas_name_prefixes");
            DropTable("hrm_ps_employees");
            DropTable("hrm_ps_absence_type");
            DropTable("hrm_ps_absence");
        }
    }
}
